let duration = 100;
/**
 * 淡出
 * @param {*} that 
 * @param {*} id 
 */
function fadeOut(that, id, fun) {
  that.animate(id, [{
    opacity: 0.0,
  }, {
    opacity: 1.0,
  }], duration, function () {
    that.setData({
      opacity: 1
    })
    this.clearAnimation(id);
    fun();
  }.bind(that))
}

/**
 * 淡入
 * @param {*} that 
 * @param {*} id 
 */
function fadeIn(that, id, fun) {
  that.animate(id, [{
    opacity: 1.0
  }, {
    opacity: 0.0
  }], duration, function () {
    that.setData({
      opacity: 0
    })
    this.clearAnimation(id);
    fun();
  }.bind(that))
}

/**
 * 从左下角放大淡出
 * @param {*} that 
 * @param {*} id 
 */
function leftBottomFadeOut(that, id, fun) {
  that.animate(id, [{
    opacity: 0.0,
    scale: [0, 0],
    transformOrigin: 'left bottom 0'
  }, {
    opacity: 1.0,
    scale: [1, 1],
    transformOrigin: 'left bottom 0'
  }], duration, function () {
    that.setData({
      opacity: 1
    })
    this.clearAnimation(id);
    fun();
  }.bind(that))
}

/**
 * 从左下角缩中淡入
 * @param {*} that 
 * @param {*} id 
 */
function leftBottomFadeIn(that, id, fun) {
  that.animate(id, [{
    opacity: 1.0,
    scale: [1, 1],
    transformOrigin: 'left bottom 0'
  }, {
    opacity: 0.0,
    scale: [0, 0],
    transformOrigin: 'left bottom 0'
  }], duration, function () {
    that.setData({
      opacity: 0
    })
    this.clearAnimation(id);
    fun();
  }.bind(that))
}

/**
 * 从底部淡出
 * @param {*} that 
 * @param {*} id 
 */
function bottomFadeOut(that, id, fun) {
  that.animate(id, [{
    opacity: 0.0,
    translateY: 100,
  }, {
    opacity: 1.0,
    translateY: 0,
  }], duration, function () {
    that.setData({
      opacity: 1
    })
    this.clearAnimation(id);
    fun();
  }.bind(that))
}

/**
 * 从底部淡入
 * @param {*} that 
 * @param {*} id 
 */
function bottomFadeIn(that, id, fun) {
  that.animate(id, [{
    opacity: 1.0,
    translateY: 0,
  }, {
    opacity: 0.0,
    translateY: 100,
  }], duration, function () {
    that.setData({
      opacity: 0
    })
    this.clearAnimation(id);
    fun();
  }.bind(that))
}

module.exports = {
  fadeOut: fadeOut,
  fadeIn: fadeIn,
  leftBottomFadeOut: leftBottomFadeOut,
  leftBottomFadeIn: leftBottomFadeIn,
  bottomFadeOut: bottomFadeOut,
  bottomFadeIn: bottomFadeIn
}